#-*-coding:utf-8-*-
from flask import Flask, request, session, jsonify,render_template
import os
import time
import json
import requests
import logging
# from apscheduler.schedulers.blocking import BlockingScheduler


app=Flask(__name__)

info_path=os.path.join(os.path.dirname(__file__),'info')
info = {"JT": 2, "XRC": 2, "ZZ": 2, "LX": 2, "WL": 2, "CYJ": 2}


def create_today_check():
    today = time.strftime('%Y-%m-%d')
    info_date=os.path.join(info_path,today)
    check_path=os.path.join(info_date,'check')
    if not os.path.exists(check_path):
        os.makedirs(info_date)
        with open(check_path,'w') as w:
            w.write(str(info))

@app.route('/dd/')
def index():

    return "OK!"

@app.route('/upInfo/',methods=['GET','POST'])
def upInfo():
    '''
    当从timeaxis服务器传来post数据时，获取并存储到本地云服务器上
    :return:
    '''

    if request.method=='GET':
        return '查询失败'

    else:

        data=request.data.decode('utf-8')
        # pipline_debug("data.decode(utf-8)成功")
        newData=eval(data)
        # pipline_debug("eval(data)成功")


        # writeInfo(newData)
        # pipline_debug("data写入本地成功")
        return "haha"

#info={"金涛":2,"夏睿晨":2,"张洲":2,"李翔":2,"吴磊":2,"陈勇瑾":2}
#info={"JT":2,"XRC":2,"ZZ":2,"LX":2,"WL":2,"CYJ":2}
def write_info(data):
    date=data['date']
    eater=data['eater']
    meal=data['meal']


def read_module(date):
    create_today_check()
    info_date=os.path.join(info_path,date)
    check_path=os.path.join(info_date,'check')
    with open(check_path,'r') as r:
        read=r.read()
        info_dict=eval(read)
    print(info_dict)



def writeNewData(date,data):
    create_today_check()
    info_date=os.path.join(info_path,date)
    check_path=os.path.join(info_date,'check')
    if os.path.exists(check_path):



def info_module():
    if not os.path.exists(info_path):
        os.makedirs(info_path)


    module_path=os.path.join(info_path,"module")
    with open(module_path,'w') as w:
        w.write(str(info))



if __name__ == '__main__':
    # app.run(host='127.0.0.1',port=8888,debug=True)
    # info_module()
    read_module('2019-09-04')